﻿using IBLL;
using IBLL.Dto;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Model;
using NPOI.XSSF.UserModel;

namespace RoomNum.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RoomNumController : ControllerBase
    {
        public RoomNumController(IRoomNumBLL bLL)
        {
            BLL = bLL;
        }

        public IRoomNumBLL BLL { get; }


        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<int> AddAsync(RoomNumber t)
        {
            return BLL.AddAsync(t);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpDelete]
        public Task<int> DeleteAsync(int id)
        {
            return BLL.DeleteAsync(id);
        }
        [HttpGet]
        public IQueryable<RoomNumber> GetAll()
        {
            return BLL.GetAll();
        }
        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="index"></param>
        /// <param name="size"></param>
        /// <param name="roomid"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        [HttpGet]
        public RoomNumPageDto GetRoomNumPage(int index, int size, int roomid, string? name)
        {
            
           return BLL.GetRoomNumPage(index, size, roomid, name);
        }
        /// <summary>
        /// 根据编号查一个
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public RoomNumber GetValue(int id)
        {
            return BLL.GetValue(id);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<int> UpdateAsync(RoomNumber t)
        {
            return BLL.UpdateAsync(t);
        }

        ///// <summary>
        ///// 导出
        ///// </summary>
        ///// <returns></returns>
        //public IActionResult ExcelRoom()
        //{
        //    var book = new XSSFWorkbook();
        //    var sheet = book.CreateSheet("房号信息表");
        //    var row = sheet.CreateRow(0);
        //    row.CreateCell(0).SetCellValue("名称");
        //    row.CreateCell(1).SetCellValue("地址");
        //    row.CreateCell(2).SetCellValue("手机号");

        //    var list = BLL.GetAll();
        //    var index = 1;
        //    foreach (var item in list)
        //    {
        //        var newrow = sheet.CreateRow(index);
        //        newrow.CreateCell(0).SetCellValue(item.Name);
        //        newrow.CreateCell(1).SetCellValue(item.Address);
        //        newrow.CreateCell(2).SetCellValue(item.Phone);
        //    }

        //    byte[] bs = null;
        //    return Ok(bs);
        //}
    }
}
